<?php

namespace App\Admin\Controllers\Api\V1;

use App\Models\User;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class UserController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('用户')
            ->description('管理')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('用户')
            ->description('详情')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('用户')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('用户')
            ->description('创建')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new User);

        date_default_timezone_set('PRC');
        $grid->model()->orderBy('created_at', 'desc');

        $grid->id('编号');
        $grid->name('用户名');
        $grid->phone('手机号');
        $grid->reference_amount('推荐奖励');
        $grid->shop_amount('商城金额');
        $grid->_lft(' lft');
        $grid->_rgt(' rgt');
        $grid->parent_id('Parent id');
        $grid->ref_code('邀请码');
        $grid->is_baned('是否解锁');
        $grid->reg_ip('注册 IP');
        $grid->login_ip('登陆 IP');
        $grid->baned_reason('冻结原因');
        $grid->is_disable_trade('是否三陪出局');
        $grid->wechat_code('微信号');
        $grid->wechat_qrcode('微信二维码');
        $grid->bank_card('银行卡');
        $grid->real_name('真实姓名');
        $grid->bank_name('开户地址');
        $grid->created_at('用户创建时间');
        $grid->updated_at('管理员修改时间');
        $grid->login_at('登陆时间');
        $grid->remember_token('是否记住我');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->id('编号');
        $show->name('用户名');
        $show->phone('手机号');
        $show->reference_amount('推荐奖励');
        $show->shop_amount('商城金额');
        $show->_lft(' lft');
        $show->_rgt(' rgt');
        $show->parent_id('Parent id');
        $show->ref_code('邀请码');
        $show->is_baned('是否解锁');
        $show->reg_ip('注册 IP');
        $show->login_ip('登陆 IP');
        $show->baned_reason('冻结原因');
        $show->is_disable_trade('是否三陪出局');
        $show->wechat_code('微信号');
        $show->wechat_qrcode('微信二维码');
        $show->bank_card('银行卡');
        $show->real_name('真实姓名');
        $show->bank_name('开户地址');
        $show->created_at('用户创建时间');
        $show->updated_at('管理员修改时间');
        $show->login_at('登陆时间');
        $show->remember_token('是否记住我');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new User);

        $form->text('name', 'Name');
        $form->mobile('phone', 'Phone');
        $form->password('password', 'Password');
        $form->text('avatar_url', 'Avatar url');
        $form->decimal('reference_amount', 'Reference amount');
        $form->decimal('shop_amount', 'Shop amount');
        $form->number('_lft', ' lft');
        $form->number('_rgt', ' rgt');
        $form->number('parent_id', 'Parent id');
        $form->text('ref_code', 'Ref code');
        $form->text('asset_password', 'Asset password');
        $form->switch('is_baned', 'Is baned');
        $form->text('reg_ip', 'Reg ip');
        $form->text('login_ip', 'Login ip');
        $form->text('baned_reason', 'Baned reason');
        $form->switch(' is_disable_trade', ' is disable trade');
        $form->text('wechat_code', 'Wechat code');
        $form->text('wechat_qrcode', 'Wechat qrcode');
        $form->text('bank_card', 'Bank card');
        $form->text('real_name', 'Real name');
        $form->text('bank_name', 'Bank name');
        $form->number('login_at', 'Login at');
        $form->text('remember_token', 'Remember token');

        return $form;
    }
}
